//package com.tool.engine.export.engine;
//
//
//import com.opencloud.base.client.model.ExportResources;
//import com.opencloud.common.exception.OpenAlertException;
//import com.opencloud.common.utils.JackJsonUtils;
//import com.tool.engine.export.output.DataOutputSource;
//import com.tool.engine.export.output.DataOutputSourceFactory;
//import com.tool.engine.export.processor.ExportTaskProcessor;
//import com.tool.engine.export.task.Task;
//import com.tool.engine.service.ExportResourcesService;
//import lombok.Getter;
//import lombok.Setter;
//import lombok.extern.slf4j.Slf4j;
//
//import javax.annotation.Resource;
//import java.util.Map;
//import java.util.Objects;
//import java.util.Optional;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.ExecutorService;
//
//@Slf4j
//public class CapacityExportTaskEngine extends AbstractExportTaskEngine {
//
//    @Setter
//    private ExecutorService threadPoolExecutor;
//
//    @Resource
//    private Map<String, ExportTaskProcessor> processors;
//
//    @Resource
//    private ExportResourcesService exportResourcesService;
//
//    @Setter
//    @Getter
//    private String filePath;
//
//    private final Map<Task<?>, ExportResources> exportResourcesMap = new ConcurrentHashMap<>();
//
//    @Override
//    public void addTask(Task<?> task, String processorName, String outPutType, Object... params) {
//        try {
//            ExportTaskProcessor processor = processors.get(processorName);
//            if (Objects.isNull(processor)) {
//                throw new OpenAlertException("processor not found");
//            }
//            DataOutputSource dataOutPutSource = DataOutputSourceFactory.createDataOutPutSource(outPutType, task, filePath);
//            if (Objects.isNull(dataOutPutSource)) {
//                throw new OpenAlertException("dataOutPutSource not found");
//            }
//            Object param = params[0];
//            if(Objects.isNull(param)){
//                throw new OpenAlertException("export task param error");
//            }
//            if(!(param instanceof ExportResources)){
//                throw new OpenAlertException("export task param not instance of ExportResources");
//            }
//
//            ExportResources exportResources = (ExportResources)param;
//            exportResourcesMap.put(task, exportResources);
//            super.processTask(task, processor, dataOutPutSource, threadPoolExecutor);
//        }catch (Exception e) {
//            log.warn("capacity engine occur exception:{}, taskName:{}", e.getMessage(), task.getFileName());
//            exportResourcesMap.remove(task);
//            throw new OpenAlertException(e.getMessage());
//        }
//    }
//
//
//    @Override
//    public void handlerException(Exception e, Task<?> task) {
//        log.warn("capacity engine handler exception:{}, taskName:{}", e.getMessage(), task.getFileName());
//        Optional.ofNullable(exportResourcesMap.get(task)).ifPresent(resource-> resource.setTaxStatus(3));
//    }
//
//    @Override
//    public void handlerComplete(Task<?> task) {
//        ExportResources resources = exportResourcesMap.remove(task);
//        log.info("capacity engine handler completed, taskName:{}, info:{}", task.getFileName(), JackJsonUtils.toJson(resources));
//        Optional.ofNullable(resources).ifPresent(item-> exportResourcesService.updateExport(item));
//    }
//
//    @Override
//    public void handlerFailed(Task<?> task) {
//        log.warn("capacity engine handler failed, taskName:{}", task.getFileName());
//        Optional.ofNullable(exportResourcesMap.get(task)).ifPresent(resource-> resource.setTaxStatus(3));
//    }
//
//    @Override
//    public void handlerSuccess(Task<?> task) {
//        log.info("capacity engine handler success, taskName:{}", task.getFileName());
//        Optional.ofNullable(exportResourcesMap.get(task)).ifPresent(resource-> resource.setTaxStatus(2));
//    }
//
//}
